home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / listvw.exe / TI1033.ASC < prev   
Text File  |  1993-06-30  |  14KB  |  595 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                           NUMBER  :  1033
  9.   VERSION  :  3.x
  10.        OS  :  DOS
  11.      DATE  :  June 30, 1993                            PAGE  :  1/9
  12.  
  13.     TITLE  :  Example of derived TListViewer for Turbo Vision.
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.   // ============ //
  21.   // TESTLIST.CPP //
  22.   // ============ //
  23.  
  24.   #define Uses_TRect
  25.   #define Uses_TKeys
  26.   #define Uses_TEvent
  27.   #define Uses_TDialog
  28.   #define Uses_TListViewer
  29.   #define Uses_TMenu
  30.   #define Uses_TMenuItem
  31.   #define Uses_TMenuBar
  32.   #define Uses_TDeskTop
  33.   #define Uses_TApplication
  34.   #include <tv.h>
  35.  
  36.   #pragma   hdrstop
  37.   #include "testlist.h"
  38.  
  39.  
  40.   class TTestApp : public TApplication
  41.   {
  42.   public:
  43.        TTestApp() : TApplication(),
  44.                    TProgInit( initStatusLine, initMenuBar,
  45.                    initDeskTop )
  46.        {}
  47.        static TMenuBar *initMenuBar( TRect r );
  48.        virtual void handleEvent( TEvent& event );
  49.   };
  50.  
  51.  
  52.  
  53.   TMenuBar *TTestApp::initMenuBar( TRect r )
  54.   {
  55.        r.b.y = r.a.y + 1;
  56.        return new TMenuBar( r, new TMenu(
  57.                       *new TMenuItem( "~L~ist", cmTTList, kbAltL )
  58.                          ));
  59.   }
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                           NUMBER  :  1033
  75.   VERSION  :  3.x
  76.        OS  :  DOS
  77.      DATE  :  June 30, 1993                            PAGE  :  2/9
  78.  
  79.     TITLE  :  Example of derived TListViewer for Turbo Vision.
  80.  
  81.  
  82.  
  83.  
  84.   void TTestApp::handleEvent( TEvent& event )
  85.   {
  86.        TApplication::handleEvent( event );
  87.  
  88.        if(  event.what == evCommand &&
  89.             event.message.command == cmTTList )
  90.        {
  91.             TView *TTLD = (TView *) validView(
  92.                                           new TTestListDialog
  93.                                              );
  94.             if( TTLD != 0 )
  95.                  deskTop->insert( TTLD );
  96.             clearEvent( event );
  97.        }
  98.   }
  99.  
  100.  
  101.  
  102.   int main()
  103.   {
  104.       TTestApp TB;
  105.       TB.run();
  106.       return 0;
  107.   }
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.   // ------------ //
  115.   // LISTVIEW.CPP //
  116.   // ------------ //
  117.  
  118.   #define Uses_TPoint
  119.   #define Uses_TRect
  120.   #define Uses_TKeys
  121.   #define Uses_TEvent
  122.   #define Uses_TDialog
  123.   #define Uses_TButton
  124.   #define Uses_TScrollBar
  125.   #define Uses_TListViewer
  126.   #define Uses_MsgBox
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                           NUMBER  :  1033
  141.   VERSION  :  3.x
  142.        OS  :  DOS
  143.      DATE  :  June 30, 1993                            PAGE  :  3/9
  144.  
  145.     TITLE  :  Example of derived TListViewer for Turbo Vision.
  146.  
  147.  
  148.  
  149.  
  150.   #include <tv.h>
  151.   #include <string.h>
  152.  
  153.   #pragma hdrstop
  154.   #include "testlist.h"
  155.  
  156.   /*
  157.    *   Data for list viewer: a collection of 80's & 90's rock
  158.    *   titles with a few earlier ones thrown in for kicks...
  159.    */
  160.   char *songTitles[] =
  161.   {
  162.        "When You Don't See Me",
  163.        "Until the End of the World",
  164.        "I'm Too Sexy",
  165.        "Hungry Like the Wolf",
  166.        "I Can't Get Enough",
  167.        "You Got Another Thing Coming",
  168.        "His Circle and Hers Meet",
  169.        "Would I Lie To You?",
  170.        "I Melt With You",
  171.        "Forever Young",
  172.        "Blue Monday",
  173.        "Owner of a Lonely Heart",
  174.        "Oh L'Amour",
  175.        "Shock the Monkey",
  176.        "If You Love Somebody Set Them Free",
  177.        "Tainted Love",
  178.        "Helpless Automaton",
  179.        "I Can't Drive 55!",
  180.        "Life is a Long Road",
  181.        "Talk Talk"
  182.   };
  183.  
  184.   const int MAXSTRINGS = (sizeof(songTitles) / sizeof( char * ));
  185.   const int MAXLENGTH  = 36;      // Length of longest song title.
  186.  
  187.  
  188.   /****************************************************************\
  189.    *
  190.    * class TTestList
  191.    *
  192.    *
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Borland C++                           NUMBER  :  1033
  207.   VERSION  :  3.x
  208.        OS  :  DOS
  209.      DATE  :  June 30, 1993                            PAGE  :  4/9
  210.  
  211.     TITLE  :  Example of derived TListViewer for Turbo Vision.
  212.  
  213.  
  214.  
  215.  
  216.    *
  217.    ****************************************************************
  218.    * TTestList::TTestList
  219.    *   Initializes range of list viewer, sets maximum length of
  220.    * individual strings and sets the grow modes so the viewer will
  221.    * grow and shrink with the dialog box window.
  222.   \****************************************************************/
  223.  
  224.   TTestList::TTestList( TRect& r,
  225.                         TScrollBar *aHSB,
  226.                         TScrollBar *aVSB ) :
  227.   TListViewer( r, 1, aHSB, aVSB )
  228.   {
  229.        maxWidth = MAXLENGTH;
  230.        setRange( MAXSTRINGS );
  231.        growMode |= gfGrowHiX | gfGrowHiY;
  232.   }
  233.  
  234.  
  235.  
  236.   /***************************************************************\
  237.    * TTestList::setRange
  238.    *   In addition to setting the range of the listviewer and the
  239.    *   vertical scrollbar, this also sets the horizontal scrollbar.
  240.    *
  241.   \***************************************************************/
  242.  
  243.   void TTestList::setRange( short range )
  244.   {
  245.        TListViewer::setRange( range );
  246.        if( hScrollBar != 0 )
  247.             hScrollBar->setRange( 0, maxWidth - size.x );
  248.   }
  249.  
  250.  
  251.  
  252.   /***************************************************************\
  253.    * TTestList::getText
  254.    *        Copies the appropriate string into the buffer passed
  255.    *        in.  If 'item' is out of range, it copies a NULL
  256.    *         string.
  257.   \***************************************************************/
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  Borland C++                           NUMBER  :  1033
  273.   VERSION  :  3.x
  274.        OS  :  DOS
  275.      DATE  :  June 30, 1993                            PAGE  :  5/9
  276.  
  277.     TITLE  :  Example of derived TListViewer for Turbo Vision.
  278.  
  279.  
  280.  
  281.  
  282.   void TTestList::getText( char *dest, short item, short maxLen )
  283.   {
  284.        if( item >= 0 && item < MAXSTRINGS )
  285.             strncpy(dest, songTitles[item], maxLen);
  286.        else
  287.             dest[0] = '\0';
  288.   }
  289.  
  290.  
  291.  
  292.   /***************************************************************\
  293.    * TTestList::changeBounds
  294.    *        If the user resizes the list viewer and there is only
  295.    *   one column, the horizontal scrollbar may need to be
  296.    *   activated if the viewer is too small (or deactivated if the
  297.    *   viewer is now large enough for a complete display.)  So we
  298.    *   check for that.  Ditto for the vertical scrollbar.
  299.   \***************************************************************/
  300.  
  301.   void TTestList::changeBounds( const TRect& bounds )
  302.   {
  303.        TListViewer::changeBounds( bounds );
  304.        if( numCols == 1 &&  hScrollBar != 0 )
  305.             hScrollBar->setParams(
  306.                                 hScrollBar->value,  // current
  307.                                                     // position in
  308.                                                     // bar
  309.                                 0,                  // minimum
  310.                                                     // length
  311.                                                     // (usually 0)
  312.                                 maxWidth - size.x,  // max length
  313.                                                     // minus width
  314.                                                     // of viewer
  315.                                 size.x - 1,         // page keys
  316.                                                     // step a full
  317.                                                     // viewer width
  318.                                 1                   // arrow keys
  319.                                                     // step one
  320.                                                     // character
  321.                                 );
  322.   }
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.   PRODUCT  :  Borland C++                           NUMBER  :  1033
  339.   VERSION  :  3.x
  340.        OS  :  DOS
  341.      DATE  :  June 30, 1993                            PAGE  :  6/9
  342.  
  343.     TITLE  :  Example of derived TListViewer for Turbo Vision.
  344.  
  345.  
  346.  
  347.  
  348.   /****************************************************************\
  349.    * TTestList::handleEvent
  350.    *        We need to handle double click messages, ensuring that
  351.    *        the mouse is on top of a valid list item and that it
  352.    *        was the left butt